It is used to initialize the members of the class VB.Net supports two types of constructors
It is used to initialize the instance and the shared members of the class
Syntax:
[Modifier] sub new ([arg info])
statement(s)
- - - - - - -
- - - - - -
End sub
Note:
Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training
It is used to initialize the shared members of the class.
Syntax:
Shared sub new ( )
statement(s)
- - - - - -
- - - - - -
End sub
Project [menu] à Add new item à Module
Name: Constructors ‘‘Demo
‘‘‘Demo on constructors . . . . .
Imports system
Module constructors ‘‘Demo
Class Test
Public i as integer
Public shared s as an integer
Sub new( ) ‘Instance constructor’
P = 100
S = 1000
End sub
Shared sub new( ) ‘Shared constructor’
S = 500
P = 500 error
End sub
End class
Sub main ( )
Console.WriteLine (“value of s before object creation: {0}”, Test.s)
Dim t As new Test
Console.WriteLine (“Value of t and s” after object creation: {0}, {1}”, t.p, Test.s)
End sub
End module
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.